<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>订单提交</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <!-- <link rel="stylesheet" href="css/weui.css"> -->
    <link rel="stylesheet" href="css/jquery-weui.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css_02/weui.css">
    <link rel="stylesheet" href="css_02/example.css">
    <script>
        function getCookie(c_name) {
            if (document.cookie.length > 0) {
                c_start = document.cookie.indexOf(c_name + "=")
                if (c_start != -1) {
                    c_start = c_start + c_name.length + 1
                    c_end = document.cookie.indexOf(";", c_start)
                    if (c_end == -1) c_end = document.cookie.length
                    return unescape(document.cookie.substring(c_start, c_end))
                }
            }
            return ""
        }

        function getQueryString(name) {
            var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }
    </script>



</head>

<body ontouchstart>

    <div class="weui_cells weui_cells_form">

        <label for="js_input1" class="weui-cell weui-cell_active">
            <div class="weui-cell__hd"><span class="weui-label">姓名</span></div>
            <div class="weui-cell__bd">
                <input id="js_input1" class="weui-input" placeholder="填写本人姓名">
            </div>
          </label>
        <label for="js_input100" class="weui-cell weui-cell_active">
           <div class="weui-cell__hd"><span class="weui-label">学号</span></div>
           <div class="weui-cell__bd">
               <input id="js_input100" class="weui-input" placeholder="填写本人学号">
           </div>
       </label>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">收货地址</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" id="city-picker" placeholder="请选择收货地址" value="">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" id="detail" placeholder="请输入详细地址">
            </div>
        </div>
        <!-- <div class="weui-cell">
            <div class="weui-cell__hd"><label for="" class="weui-label">城市</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" id="city-picker2" placeholder="请选择发货城市" value="">
            </div>
        </div> -->

        <label for="js_input3" class="weui-cell weui-cell_active">
            <div class="weui-cell__hd"><span class="weui-label">联系电话</span></div>
            <div class="weui-cell__bd">
                <input id="js_input3" class="weui-input" placeholder="填写绑定的电话号码" type="number" pattern="[0-9]*">
            </div>
          </label>
    </div>
    <label for="js_input1" class="weui-cell weui-cell_active">
       <div class="weui-cell__bd">
           <div id="uidt"></div>
       </div>
   </label>





    <!--    <a href="javascript:" role="button" id="i5" class="weui-btn weui-btn_primary">提交</a>-->
    <button class="weui-btn weui-btn_primary">提交</button>

    <script src="js/jquery.min.js"></script>
    <script src="js/jquery-weui.min.js"></script>
    <script src="js/city-picker.min.js"></script>
    <script>
        $("#city-picker").cityPicker({
            title: "请选择收货地址"
        });
        $("#city-picker2").cityPicker({
            showDistrict: false
        });
    </script>
    <script>
        $('button').eq(0).click(function() {
            phoneNum = $("#js_input3").val();
            console.log(phoneNum);
            let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(phoneNum)) {
                return document.getElementById('uidt').innerHTML = '   错误:请输入正确的手机号!';
            } else {
                console.log("pass");
                var ID = getQueryString("ID");
                var uid = getCookie("userId");
                $.ajax({
                    //url
                    url: 'http://139.224.246.43:8084/orderapi/chooseGift',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    //参数
                    data: JSON.stringify({
                        gift_id: parseInt(ID),
                        name: $("#js_input1").val(),
                        student_id: $("#js_input100").val(),
                        address: $("#city-picker").val(),
                        address_detail: $("#detail").val(),
                        phone_number: $("#js_input3").val(),
                        uid: uid,
                    }),
                    //请求类型
                    type: 'POST',
                    //响应体结果
                    dataType: 'json',
                    //成功的回调
                    success: function(data) {
                        console.log(data.data);
                        var order_id = data.data.order_id;
                        console.log(order_id);
                        $.showLoading();
                        setTimeout(function() {
                            $.hideLoading();
                            location.replace("./GetCurrentOrder.html?order_id=" + order_id);
                        }, 3000)
                    },
                    error: function() {
                        console.log('出错了');
                    },
                })
            }
            // $.ajax({
            //     //url
            //     url: 'http://127.0.0.1:8080/order',
            //     //参数
            //     data: {
            //         name:$("#js_input1").val(),
            //         address:$("#city-picker").val(),
            //         address_detail:$("#detail").val(),
            //         phone:$("#js_input3").val(),
            //     },
            //     //请求类型
            //     type: 'POST',
            //     //响应体结果
            //     dataType: 'json',
            //     //成功的回调
            //     success: function(data){
            //         $.showLoading();
            //         setTimeout(function() {
            //             $.hideLoading();
            //             location.replace("./查看订单.html");
            //         }, 3000)
            //     },
            //     error: function(){
            //         console.log('出错了');
            //     },
            // })

        })
    </script>


</body>

</html>